package com.jingsheng.jingshengcity.mvp.ui.activity.wallet;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;

import com.jakewharton.rxbinding2.widget.RxTextView;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.UiUtils;
import com.jingsheng.jingshengcity.R;
import com.jingsheng.jingshengcity.di.component.DaggerBindBankCardNextComponent;
import com.jingsheng.jingshengcity.di.module.BindBankCardNextModule;
import com.jingsheng.jingshengcity.mvp.contract.BindBankCardNextContract;
import com.jingsheng.jingshengcity.mvp.presenter.BindBankCardNextPresenter;

import butterknife.BindView;
import io.reactivex.Observable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * Created by Administrator on 2017/5/13.
 */

public class BindBankCardNextActivity extends BaseActivity<BindBankCardNextPresenter> implements BindBankCardNextContract.View {

    @NonNull
    @BindView(R.id.et_phone)
    EditText mEtPhone;
    @NonNull
    @BindView(R.id.btn_next)
    Button mBtnNext;

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerBindBankCardNextComponent
                .builder()
                .appComponent(appComponent)
                .bindBankCardNextModule(new BindBankCardNextModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView() {
        setTitle("银行卡绑定");
        return R.layout.activity_bind_bank_card_next;
    }

    @Override
    public void initData() {
        Observable<CharSequence> observableCode = RxTextView.textChanges(mEtPhone);

        observableCode.map(new Function<CharSequence, Boolean>() {
            @Override
            public Boolean apply(@io.reactivex.annotations.NonNull CharSequence charSequence) throws Exception {
                if (TextUtils.isEmpty(charSequence)) {
                    return false;
                }
                return true;
            }
        }).subscribe(new Consumer<Boolean>() {
            @Override
            public void accept(@io.reactivex.annotations.NonNull Boolean aBoolean) throws Exception {
                if (aBoolean) {
                    mBtnNext.setEnabled(true);
                } else {
                    mBtnNext.setEnabled(false);
                }
            }
        });
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        UiUtils.SnackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        UiUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


}